package com.iespring.service.app.feedback;

import com.iespring.bean.admin.user.entity.MallFeedback;
import com.iespring.bean.admin.user.entity.MallUser;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.mapper.admin.MallFeedbackMapper;
import com.iespring.util.UserInfoUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Auth: 杨宇健
 * Time: 2023/1/1 14:41
 * Description:
 **/
@Service
public class WxFeedbackServiceImpl implements WxFeedbackService {

    @Resource
    MallFeedbackMapper feedbackMapper;

    @Override
    public BaseRespVo submit(MallFeedback feedback) {

        MallUser user = UserInfoUtils.getUser();
        if (user == null || user.getId() == null) {
            return BaseRespVo.error("请重新登录", 500);
        }
        feedback.setUserId(user.getId());
        Date date = new Date();
        feedback.setAddTime(date);
        feedback.setUpdateTime(date);
        feedback.setUsername(user.getUsername());
        feedback.setStatus(0);
        feedback.setDeleted(false);
        int affect = feedbackMapper.insert(feedback);
        if (affect == 0) {
            BaseRespVo.error("反馈失败", 500);
        }
        return BaseRespVo.ok();
    }
}
